//
//  LabelDetailViewController.m
//  拖小延闹钟
//
//  Created by rimi on 15/10/12.
//  Copyright (c) 2015年 Liukai. All rights reserved.
//

#import "LabelDetailViewController.h"

@interface LabelDetailViewController ()
@property (nonatomic, strong) UITextField *textfield;
@end

@implementation LabelDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initInterface];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)initInterface {
    UIView *navBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64)];
    navBarView.backgroundColor = [UIColor colorWithWhite:0.900 alpha:1.000];
    //title
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds) / 2 - 40, 20, 120, 40)];
    titleLabel.text = @"添加标签";
    titleLabel.font = [UIFont systemFontOfSize:22];
    //personalButton
    UIButton *personalButton = [UIButton buttonWithType:UIButtonTypeCustom];
    personalButton.frame = CGRectMake(10, 20, 40, 40);
    [personalButton setImage:[UIImage imageNamed:@"后退"] forState:UIControlStateNormal];
    [personalButton addTarget:self action:@selector(backToLast:) forControlEvents:UIControlEventTouchUpInside];
    [navBarView addSubview:personalButton];
    [navBarView addSubview:titleLabel];
    [self.view addSubview:navBarView];
    UITextField *aTextfield = [[UITextField alloc] initWithFrame:CGRectMake(30, CGRectGetHeight(self.view.bounds) / 2 - 30, CGRectGetWidth(self.view.bounds) * 3/4, 30)];
    aTextfield.placeholder = @"请输入标签信息";
    aTextfield.layer.borderWidth = 1;
    aTextfield.layer.cornerRadius = 20;
    aTextfield.layer.borderColor = [UIColor blackColor].CGColor;
    aTextfield.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:aTextfield];
    self.textfield = aTextfield;
    //deleteButton
    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [deleteButton setBackgroundImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
    deleteButton.frame = CGRectMake(CGRectGetWidth(self.view.bounds) - 50, CGRectGetHeight(self.view.bounds) / 2 - 30, 30, 30);
    
    [self.view addSubview:deleteButton];
    [deleteButton addTarget:self action:@selector(deleteInput:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)backToLast:(UIButton *)sender {
    if (self.backMessage) {
        self.backMessage(self.textfield.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)deleteInput:(UIButton *)sender {
    self.textfield.text = @"";
}
- (void)sendMessage:(BackMessage)backMessage {
    self.backMessage = backMessage;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
